<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <input type="text">
        <button>添加</button>
    </div>
    <div id="box">
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
    </div>
    <script>
        // 伪代码
        // 获取元素
        let inp = document.querySelector('input');
        let btn = document.querySelector('button');
        let list = document.querySelector('#box');
        // 绑定事件
        btn.addEventListener(
            'click',
            function(){
                const value = inp.value;
                if(value.trim() === ''){
                    alert('请输入内容');
                    return;
                }
                let div = document.createElement('div');
                // div.classList.add('item');
                div.textContent = value;
                list.appendChild(div);
            }
        )    
    </script>
</body>
</html>